#include "addguest.h"
#include "ui_addguest.h"
#include <QDateTime>

AddGuest::AddGuest(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::AddGuest)
{
    ui->setupUi(this);
    sexBtn = new QButtonGroup();
    sexBtn->setExclusive(true);
    sexBtn->addButton(ui->sex_male, 0);
    sexBtn->addButton(ui->sex_female, 1);
}

AddGuest::~AddGuest()
{
    delete ui;
}

void AddGuest::setSQL(SQLConn *& conn)
{
    sql = conn;
}

void AddGuest::on_pushButton_2_clicked()
{
    this->close();
}

void AddGuest::on_pushButton_clicked()
{
    m_name = ui->le_name->text();
    m_age = ui->sb_age->text().toInt();
    if (sexBtn->checkedId() == 0)
    {
        m_sex ="男";
    }
    else
    {
        m_sex ="女";
    }
    m_phone = ui->le_phone->text();
    QDateTime current_date_time =QDateTime::currentDateTime();
    QString current_date =current_date_time.toString("yyyy/MM/dd hh:mm:ss");
    m_time = current_date;
    sql->add_guest(m_name, m_sex, m_age, m_phone, m_time);
    this->close();
}
